﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace CapaPresentacion.Commands
{
    public class RelayCommand : ICommand
    {
        private readonly Action<Object> execute;
        private readonly Predicate<Object> canExecute;

        public RelayCommand(Action<Object> _execute) : this(_execute, null) { }

        public RelayCommand(Action<object> _execute, Predicate<Object> _canExecute)
        {
            this.execute = _execute;
            this.canExecute = _canExecute ?? (param => true);
        }

        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return this.canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            this.execute(parameter);
        }

        #endregion
    }
}
